package graph

import (
	"container/list"
	"fmt"
)

func GraphDFS(graph Graph) {
	nodeSet := map[*Node]struct{}{}
	stack := list.New()
	stack.PushBack(graph.Nodes[1])
	nodeSet[graph.Nodes[1]] = struct{}{}
	fmt.Println(graph.Nodes[1].Val)
	for stack.Len() > 0 {
		node := stack.Remove(stack.Back()).(*Node)
		for _, next := range node.Nexts {
			if !Contains1(nodeSet, next) {
				stack.PushBack(node)
				stack.PushBack(next)
				nodeSet[next] = struct{}{}
				fmt.Println(next.Val)
				break
			}
		}
	}
}